// 引入express
const express = require('express');
// 引入body-parser
const bodyParser = require('body-parser')
// 引入cors
const cors = require('cors')
// 实例化
const app = express();

app.use(cors())

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())

// const record = function (req, res, next) {
//     console.log("这是record1中间件");
//     next();
// }

// const record2 = function (req, res, next) {
//     console.log("这是record2中间件");
//     next();
// }
// app.use(record2);
// app.use(record);


const userRouter = require('./routers/userRouter')
// app.use(userRouter) // 不加前缀 http://localhost:3000/findUser
app.use('/user', userRouter) // 加前缀 http://localhost:3000/user/findUser

app.use('/static', express.static('static'));

// 定义一个错误级别中间件
const errFun = function (err, req, res, next) {
    res.send({
        msg: `错误级别中间件返回:${err.message}`,
        status: false
    })
}
app.use(errFun);


app.listen(3000, () => {
    console.log('服务启动于：http://localhost:3000');
})